//
//  BookManager.m
//  Objective-C HomeWork 03 - NSString NSArray NSMutableArray
//
//  Created by dllo on 16/7/6.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "BookManager.h"

@implementation BookManager

- (instancetype)initWithBookArray:(NSMutableArray *)bookArray {
    self = [super init];
    if (self) {
        _bookArray = bookArray;
    }
    return self;
}
+ (instancetype)bookManagerWithBookArray:(NSMutableArray *)bookArray {
    return [[BookManager alloc] initWithBookArray:bookArray];
}

- (void)addBook:(Book *)newBook {
    [self.bookArray addObject:newBook];
}

- (void)deleteBook:(Book *)book {
    [self.bookArray removeObject:book];
}
- (void)sortBooKAndChangPriceByBookName:(NSString *)bookName bookPrice:(NSInteger)price {
    for (NSInteger i = 0; i < self.bookArray.count; i++) {
        Book *book = [self.bookArray objectAtIndex:i];
        if ([book.bookName isEqualToString:bookName]) {
            [book setBookPrice:price];
            NSLog(@"修改成功！");
            NSLog(@"book = %@",book);
        }
        NSLog(@"书库中没有所查找的书籍！");
        
        
    }
}

- (void)disPlay {
    NSMutableArray *bookName = [NSMutableArray array];
    for (NSInteger i = 0; i < self.bookArray.count ; i++) {
        Book *book = [self.bookArray objectAtIndex:i];
        [bookName addObject:book.bookName];
    }
    NSLog(@"bookName = %@",bookName);
}
@end
